# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=pyside2-tools
pkgbase=mingw-w64-${_realname}-qt5
pkgname=(${MINGW_PACKAGE_PREFIX}-${_realname}-qt5)
pkgdesc="PySide2 lupdate, rcc, and uic development tools (mingw-w64)"
pkgver=5.14.2
pkgrel=1
pkgdesc="Python bindings for Qt5 (mingw-w64)"
arch=('any')
url="https://doc-snapshots.qt.io/qtforpython/"
license=("LGPL")
depends=("${MINGW_PACKAGE_PREFIX}-qt5")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-pyside-qt5=${pkgver}"
             "${MINGW_PACKAGE_PREFIX}-qt5")
options=('staticlibs' 'strip')
source=(https://download.qt.io/official_releases/QtForPython/pyside2/PySide2-${pkgver}-src/pyside-setup-opensource-src-${pkgver}.tar.xz)
sha256sums=('7c7af33792de57255dbdc165c808e1f03a2520295c5922d9897aca8ad1be92b3')

prepare() {
  cd ${srcdir}/pyside-setup-opensource-src-${pkgver}
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}-${pyv}
  
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    ${_conf} \
    -DPYTHON_EXECUTABLE=${MINGW_PREFIX}/bin/python.exe \
    ../pyside-setup-opensource-src-${pkgver}/sources/pyside2-tools
  
  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install

  ${MINGW_PREFIX}/bin/python -m compileall "${pkgdir}${MINGW_PREFIX}"/lib/python3*/site-packages/pyside2uic/
  ${MINGW_PREFIX}/bin/python -O -m compileall "${pkgdir}${MINGW_PREFIX}"/lib/python3*/site-packages/pyside2uic/
}
